
package edu.tongji.jiaowu.dao.jdbc;
 
import java.util.List;

import edu.tongji.jiaowu.dao.ScoreLevelDao;
import com.tongji.quickCRUDQ.define.Row;
import com.tongji.quickCRUDQ.model.CommonBean;
import com.tongji.quickCRUDQ.dao.jdbc.BaseDaoJdbc;
import com.tongji.quickCRUDQ.exception.FormatException;

public class ScoreLevelDaoJdbc extends BaseDaoJdbc implements ScoreLevelDao {
	String tableName="T_SCORE_LEVEL";
	String beanName="scoreLevel";
	
	public CommonBean createScoreLevel(){
		CommonBean scoreLevels=this.createBean(tableName,beanName);
                return scoreLevels;		
	}
	
/*
	public CommonBean findScoreLevels(String refid) {
		CommonBean scoreLevels=this.createScoreLevel();
		String sql="select * from T_SCORE_LEVEL where refid=?";
		List data=this.getCommonDao().select(sql,new String[]{refid});
		scoreLevels.addData(data);
                return scoreLevels;
       }
*/
	public CommonBean findScoreLevelById(String id) {
		CommonBean scoreLevels=this.createScoreLevel();
		String sql="select * from T_SCORE_LEVEL where id=?";
		List data=this.getCommonDao().select(sql,new String[]{id});
		scoreLevels.addData(data);
    return scoreLevels;
  }
  
	public CommonBean findAllScoreLevels() {
		CommonBean scoreLevels=this.createScoreLevel();
		String sql="select * from T_SCORE_LEVEL ";
		List data=this.getCommonDao().select(sql,new String[]{});
		scoreLevels.addData(data);
    return scoreLevels;
  }
	public void insertScoreLevel(CommonBean scoreLevelBean){
		List data=scoreLevelBean.getData();
		Row row=this.getRow(tableName);
		this.getCommonDao().templateBatchInsert(row,data,this.getIdGenerator());
	}

	public CommonBean findScoreLevel(String scoreLevel, String scoreFormat) {
		String sql="select * from t_score_level where score_level=?";
		List data;
		//TODO mytodo 硬编码"百分制(02)"
		if ("02".equals(scoreFormat)) {//百分制
			sql="select * from t_score_level where ?>=lower_limit and ?<upper_limit";
			data=this.getCommonDao().select(sql,new String[]{scoreLevel,scoreLevel});
		}else{//五级制、二级制
			data=this.getCommonDao().select(sql,new String[]{scoreLevel});
		}
		if(data.size()==0){
			throw new FormatException("无此成绩等级:"+scoreLevel);
		}
		CommonBean scoreLevelBean=this.createScoreLevel();
		scoreLevelBean.addData(data);
		return scoreLevelBean;
	}
}

